package network.TCPDome;


import jdk.nashorn.internal.runtime.Scope;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * 假如你需要设计一个小游戏,当客户端将一段文字发送给服务器后,服务器会将文字反转然后再发回给客户端;请使用程序实现效果;
 *
 * **要求:**
 *
 * 客户端通过键盘输入得到一个字符串发给服务器.(键盘输入不要求循环,发一次即可,如果想增强,也可以把键盘输入加上循环,并自己制定结束的标记)
 */
public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1",10086);
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入一句话：");
        String s = scanner.next();
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write(s.getBytes());
        socket.shutdownOutput();

        InputStream inputStream = socket.getInputStream();
        byte[] bytes = new byte[1024];
        int len;
        while ((len = inputStream.read(bytes) )!= -1) {
            System.out.println(new String(bytes,0,len));
        }

        socket.close();
    }
}
